package cn.gwm.flink.streaming.business;

import lombok.Data;
import org.apache.flink.api.java.tuple.Tuple2;

import java.util.List;

/**
 * @Author Liu.Nanfang
 * @Date 2023/3/28 13:17
 * @Description 功能配置信息计算下发配置
 */
@Data
public class ModuleConfData {
    /**
     * 预约充电
     */
    public static final String YYCD_FINCTION_TYPE = "yycd";
    public static final Integer CALCULATOR_NONE_ENUM = 0;

    private List<ModuleConf> globalModuleConfigData;

    private Tuple2<Boolean, Boolean> getCalculationAndIssued(ModuleConf params) {
        return new Tuple2(!params.getCalculation().equals(CALCULATOR_NONE_ENUM), !params.getIssued().equals(CALCULATOR_NONE_ENUM));
    }

    /**
     * 根据车型查找是否数据
     *
     * @param vehicleType
     * @return
     */
    public boolean getConfigByVehicleType(String vehicleType) {
        return globalModuleConfigData.stream().filter(item -> item.getVehicleType().equals(vehicleType)).count() > 0;
    }

    /**
     * 根据车型与服务类型查找电相关配置是否需要下发与计算
     *
     * @param vehicleType
     * @return Tuple2(calculation, issued)
     */
    public Tuple2<Boolean, Boolean> getConfigByType(String vehicleType, String serviceFunctionType) {
        return globalModuleConfigData.stream().filter(item -> item.getVehicleType().equals(vehicleType) &&
                        serviceFunctionType.equals(item.getServiceFunctionType())).map(item -> getCalculationAndIssued(item))
                .findFirst().orElse(new Tuple2(false, false));
    }

    /**
     * 查找预约充电相关配置是否需要下发与计算
     *
     * @param vehicleType
     * @return Tuple2(calculation, issued)
     */
    public Tuple2<Boolean, Boolean> getConfigByReserveChargeType(String vehicleType) {
        return getConfigByType(vehicleType, YYCD_FINCTION_TYPE);
    }

    @Data
    public static class ModuleConf {
        /**
         * 车型
         */
        private String vehicleType;
        /**
         * CC码
         */
        private String modelName;

        /**
         * 新增字典表时候的功能唯一标识
         */
        private String serviceFunctionType;
        /**
         * 部件类型
         */
        private String partType;
        /**
         * 软件版本
         */
        private String partTypeVersion;
        /**
         * 动力类型
         */
        private String powerTrain;
        /**
         * 0无计算1有计算
         */
        private Integer calculation;
        /**
         * 0无下发2有下发
         */
        private Integer issued;
    }


}
